package com.controller;

import com.exception.ValidateException;
import com.pojo.Tel;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;

@RestController
public class TelCtrl {

    @GetMapping(value = "tel")
    public ResponseEntity tel(@Valid Tel tel, BindingResult bindingResult){
        if (bindingResult.hasErrors()){
            throw new ValidateException(bindingResult.getFieldErrors());
        }
        return ResponseEntity.ok(tel);
    }
}
